<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        <div>
            数量  <input type="text" id="goodsnum" />
        </div>
        <div>
            价格  <input type="text" id="goodsprice" />
        </div>
        <div>
            小计  <span id="total"></span>
        </div>
    </div>
</body>
<script>
    let  goodsnumInput = document.getElementById("goodsnum");
    let  goodspriceInput  = document.getElementById("goodsprice");
    let  totalSpan  = document.getElementById("total");
    let  info = {

    }
    let  goodsnum=0;
    let  goodsprice = 0;

    Object.defineProperty(info,"goodsnum",{
        set(num){
            goodsnum = num;
            // console.log(_goodsnum);
            complier();
        },
        get(){
            return  goodsnum;
        }
    })
    Object.defineProperty(info,"goodsprice",{
        set(price){
            goodsprice = price;
            // console.log(_goodsprice);
            complier();
        },
        get(){
            return  goodsprice;
        }
    })

    function  complier(){

        totalSpan.innerHTML  = info.goodsnum*info.goodsprice;
    }
    goodsnumInput.oninput  = function(){
        info.goodsnum = goodsnumInput.value;
    }

    goodspriceInput.oninput  = function(){
        info.goodsprice = goodspriceInput.value;
    }


</script>
</html>